/*
 * Te_Psw_View.java
 *
 * Created on 2009年2月23日, 下午11:05
 */
package view;

import model.Psw_Comp_Model;
import model.Te_Info_Model;
import ucm.Card_UC;
import ucm.Setting_UC;
import xml.Te_Info_XML;

/**
 *
 * @author  马凯
 */
public class Te_Psw_View extends javax.swing.JFrame {

    private static Te_Psw_View tpv;
    private Card_UC cuc;
    private Te_Login_View tlv;
    private Te_Info_Model tim;
    private String id;
    private String psw;

    /** Creates new form Te_Psw_View */
    public Te_Psw_View() {
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        psw_La = new javax.swing.JLabel();
        psw_TF = new javax.swing.JTextField();
        cancel_Bu = new javax.swing.JButton();
        ok_Bu = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ISC_SING IN");

        psw_La.setText("Password:");

        cancel_Bu.setText("Cancel");
        cancel_Bu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancel_BuActionPerformed(evt);
            }
        });

        ok_Bu.setText("O k");
        ok_Bu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ok_BuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(psw_La)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(psw_TF, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(ok_Bu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancel_Bu)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(psw_La)
                    .addComponent(psw_TF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancel_Bu)
                    .addComponent(ok_Bu))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ok_BuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ok_BuActionPerformed
        psw = this.getFrameModel().getPsw_TF().getText();
        tim = Te_Info_XML.getInstance(tlv).run();
        id = tlv.getIDModel().getUserID();
        psw = this.psw_TF.getText();
        if (id.equals(tim.getName()) && psw.equals(tim.getPsw())) {
            Setting_UC.getInstance().run();
            this.setVisible(false);
        } else {
            tlv.setVisible(true);
            this.setVisible(false);
        }
    }//GEN-LAST:event_ok_BuActionPerformed

    private void cancel_BuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_BuActionPerformed
        tlv.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_cancel_BuActionPerformed
    public Psw_Comp_Model getFrameModel() {
        Psw_Comp_Model pcm = new Psw_Comp_Model();
        pcm.setCan_Bu(cancel_Bu);
        pcm.setOk_Bu(ok_Bu);
        pcm.setPsw_TF(psw_TF);
        return pcm;
    }

    public static Te_Psw_View getInstance(Card_UC cuc, Te_Login_View tlv) {
        if (tpv == null) {
            tpv = new Te_Psw_View();
            tpv.tlv = tlv;
        }
        return tpv;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Te_Psw_View().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancel_Bu;
    private javax.swing.JButton ok_Bu;
    private javax.swing.JLabel psw_La;
    private javax.swing.JTextField psw_TF;
    // End of variables declaration//GEN-END:variables
}
